//根据用户姓名模糊查询
function queryUserByName() {
    let username = $("#username").val();
    let data = {"username": username};
    $.post('http://localhost:8080/user/queryByName', data, function (result) {
        let res = result.object;
        let str = "";
        for (let i = 0; i < res.length; i++) {
            str += "<tr><td>\n" +
                "<input type='checkbox' name='checkbox' value='" + res[i].userid + "'/>\n" +
                "</td>";
            str += "<td>" + res[i].userid + "</td>";
            str += "<td>" + res[i].username + "</td>";
            str += "<td>" + res[i].password + "</td>";
            str += "<td>" + res[i].sex + "</td>";
            str += "<td>" + res[i].faculty + "</td>";
            if (res[i].priority == 2) {
                str += "<td>管理员</td>";
            } else if (res[i].priority == 1) {
                str += "<td>教师</td>";
            } else if (res[i].priority == 0) {
                str += "<td>学生</td>";
            } else {
                alert("请求出错");
            }
            str += "<td class=\"td-manage\">\n" +
                "<a title='编辑' onclick=\"user_edit_show('编辑','user-edit.html'," + res[i].userid + ")\" href='javascript:;'>\n" +
                "<i class=\"layui-icon\">&#xe642;</i>\n" +
                "</a>\n" +
                "<a title='删除' onclick='user_del(this," + res[i].userid + ")' href='javascript:;'>\n" +
                "<i class=\"layui-icon\">&#xe640;</i>\n" +
                "</a>\n" +
                "</td></tr>";
        }
        $("#users").html(str);
    });
}

//根据实验室名称模糊查询
function queryLabByName() {
    let labname = $("#labname").val();
    let data = {"labname": labname};
    $.post('http://localhost:8080/lab/findLabByName', data, function (result) {
        let res = result.object;
        let str = "";
        if (result.code == '200') {
            for (let i = 0; i < res.length; i++) {
                str += "<tr><td>\n" +
                    "<input type='checkbox' name='checkbox' value='" + res[i].labid + "'/>\n" +
                    "</td>";
                str += "<td>" + res[i].labid + "</td>";
                str += "<td>" + res[i].labname + "</td>";
                str += "<td>" + res[i].address + "</td>";
                str += "<td>" + res[i].seats + "</td>";
                str += "<td>" + res[i].remark + "</td>";
                str += "<td>" + res[i].faculty + "</td>";
                if (res[i].role == 0) {
                    str += "<td>公用实验室</td>";
                } else if (res[i].role == 1) {
                    str += "<td>专用实验室</td>";
                } else {
                    alert("出现错误");
                }
                str += "<td class=\"td-manage\">\n" +
                    "<a title=\"编辑\"  onclick=\"user_edit_show('编辑','laboratory-edit.html'," + res[i].labid + ")\" href=\"javascript:;\">\n" +
                    "<i class=\"layui-icon\">&#xe642;</i>\n" +
                    "</a>\n" +
                    "<a title=\"删除\" onclick=\"lab_del(this," + res[i].labid + ")\" href=\"javascript:;\">\n" +
                    "<i class=\"layui-icon\">&#xe640;</i>\n" +
                    "</a>\n" +
                    "<a title=\"预约\" onclick='lab_book(\"预约\",\"../../templates/bookLab.html\"," + res[i].labid + ",\"" + res[i].labname + "\")' href=\"javascript:;\">\n" +
                    "<img src='../images/book.png' width='20' height='20' alt='预约'/>\n" +
                    "</a>\n" +
                    "</td></tr>";
                $("#labs").html(str);
            }
        } else {
            alert("请求失败");
        }
    });
}

//根据实验室名称模糊查询订单信息
function queryByLabName() {
    let labname = $("#labname").val();
    let data = {"labname": labname};
    $.post('http://localhost:8080/record/queryRecordByLabName', data, function (result) {
        let res = result.object;
        let str = "";
        for (let i = 0; i < res.length; i++) {
            str += "<tr><td>\n" +
                "<input type='checkbox' name='checkbox' value='" + res[i].recordid + "'/>\n" +
                "</td>";
            str += "<td>" + res[i].recordid + "</td>";
            str += "<td>" + res[i].labid + "</td>";
            str += "<td>" + res[i].labname + "</td>";
            str += "<td>" + res[i].userid + "</td>";
            str += "<td>" + res[i].username + "</td>";
            str += "<td>" + res[i].faculty + "</td>";
            str += "<td>" + res[i].bookTime + "</td>";
            str += "<td>" + res[i].state + "</td>";
            str += "<td class=\"td-manage\">\n" +
                // "<a title='编辑' onclick=\"user_edit_show('编辑','order-edit.html'," + res[i].recordid + ")\" href='javascript:;'>\n" +
                // "<i class=\"layui-icon\">&#xe642;</i>\n" +
                // "</a>\n" +
                "<a title='删除' onclick='record_del(this," + res[i].recordid + ")' href='javascript:;'>\n" +
                "<i class=\"layui-icon\">&#xe640;</i>\n" +
                "</a>\n" +
                "</td></tr>";
        }
        $("#record").html(str);
    });
}